<?php

namespace Acesso\Filter;

use Zend\InputFilter\Factory as InputFactory;     // <-- Add this import
use Zend\InputFilter\InputFilter;                 // <-- Add this import
use Zend\InputFilter\InputFilterAwareInterface;   // <-- Add this import
use Zend\InputFilter\InputFilterInterface;        // <-- Add this import

class Login implements InputFilterAwareInterface
{

   
    public $usuario;
    public $senha;
    protected $inputFilter;                       // <-- Add this variable

    public function exchangeArray( $data )
    {
      
        $this->usuario = (isset( $data['usuario'] )) ? $data['usuario'] : null;
        $this->senha   = (isset( $data['senha'] )) ? $data['senha'] : null;

    }

    // Add content to this method:
    public function setInputFilter( InputFilterInterface $inputFilter )
    {
        throw new \Exception( "Not used" );

    }

    public function getInputFilter()
    {
        if (!$this->inputFilter) {
            $inputFilter = new InputFilter();
            $factory     = new InputFactory();

            $inputFilter->add( $factory->createInput( array(
                        'name'       => 'usuario',
                        'required'   => true,
                        'filters'    => array(
                            array('name' => 'StripTags'),
                            array('name' => 'StringTrim'),
                        ),
                        'validators' => array(
                            array(
                                'name'    => 'StringLength',
                                'options' => array(
                                    'encoding' => 'UTF-8',
                                    'min'      => 1,
                                    'max'      => 100,
                                ),
                            ),
                        ),
            ) ) );

            $inputFilter->add( $factory->createInput( array(
                        'name'       => 'senha',
                        'required'   => true,
                        'filters'    => array(
                            array('name' => 'StripTags'),
                            array('name' => 'StringTrim'),
                        ),
                        'validators' => array(
                            array(
                                'name'    => 'StringLength',
                                'options' => array(
                                    'encoding' => 'UTF-8',
                                    'min'      => 1,
                                    'max'      => 100,
                                ),
                            ),
                        ),
            ) ) );

            $this->inputFilter = $inputFilter;
        }

        return $this->inputFilter;

    }

}
